﻿using Infrastructures;
using IRepository;
using Newtonsoft.Json.Linq;
using Spring.Data.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RepositoryMySQL
{
    public class AdminRepository:IAdminRepository
    {
        public JObject ListStudent(int start, int limit)
        {
            string strSql = @"select sql_calc_found_rows u.userno, u.CreateTime,u.Status,a.Name,a.ChargeName,u.remark, u.AuditName from userinfo u 
                                     LEFT JOIN relationship r on u.userno=r.noto
                                     LEFT JOIN association a on r.nofrom =  a.associationno
                                     LEFT JOIN student s on s.studentno=u.userno Where Role='Student' AND u.Status <>'Verified' ORDER BY u.UpdateTime  limit @start,@limit;select found_rows()";

            start = start == 0 ? 1 : start;
            limit = limit == 0 ? 10 : limit;

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("start", DbType.Int32).Value = (start - 1) * limit;
            p.Add("limit", DbType.Int32).Value = limit;

            return QueryHelper.QueryPagingJson(strSql, p);
        }

    }
}
